<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.prime.com.tr/ui">

    <body>

        <ui:composition template="./productionReport.xhtml">

            <ui:define name="tabContent">

                <h:form>
                    <p:panel>

                        <h:panelGrid columns="2" rendered="#{!smsKeywordServiceMappingBean.edit}">
                            Từ khóa*  <p:inputText value="#{smsKeywordServiceMappingBean.selected.contentKeyword}" 
                                                   required="true" requiredMessage="Từ khóa không được để trống"/>
                            Cú pháp*  <p:inputText value="#{smsKeywordServiceMappingBean.selected.syntaxPrefix}" 
                                                   required="true" requiredMessage="Cú pháp không được để trống"/>
                            
                            Chú thích <p:inputTextarea value="#{smsKeywordServiceMappingBean.selected.description}"/>
                        </h:panelGrid>

                        <h:panelGrid columns="5">
                            <p:commandButton ajax="false" value="Thêm mới" rendered="#{!smsKeywordServiceMappingBean.edit}" action="#{smsKeywordServiceMappingBean.create()}"/>
                            <p:commandButton ajax="false" value="Cập nhật" rendered="#{smsKeywordServiceMappingBean.edit}" action="#{smsKeywordServiceMappingBean.edit()}"/>
                            <p:commandButton ajax="false" value="Hủy bỏ" immediate="true" action="#{smsKeywordServiceMappingBean.resetToCreateForm()}"/>
                        </h:panelGrid>
                    </p:panel>
                </h:form>
                <br/>
                <h:form>
                    <p:dataTable id="table" value="#{smsKeywordServiceMappingBean.list}" var="item" paginator="#{smsKeywordServiceMappingBean.list.size() >20}" rows="20" 
                                 selection="#{smsKeywordServiceMappingBean.selectedList}" selectionMode="multiple">

                        <f:facet name="header">  
                            <div align="left">
                                <p:menuButton value="Xử lý bản ghi được chọn">  
                                    <p:menuitem ajax="false" value="Chỉnh sửa" icon="ui-icon ui-icon-pencil" action="#{smsKeywordServiceMappingBean.prepareEdit()}"/>
                                    <p:menuitem value="Xóa" icon="ui-icon ui-icon-close" onclick="deleteConfirm.show()" />   
                                </p:menuButton> 
                            </div>
                        </f:facet> 

                        <f:facet name="footer">  
                            <div align="left">
                                <p:menuButton value="Xử lý bản ghi được chọn">  
                                    <p:menuitem ajax="false" value="Chỉnh sửa" icon="ui-icon ui-icon-pencil" action="#{smsKeywordServiceMappingBean.prepareEdit()}"/>
                                    <p:menuitem value="Xóa" icon="ui-icon ui-icon-close" onclick="deleteConfirm.show()" />   
                                </p:menuButton> 
                            </div>
                        </f:facet> 

                        <p:column headerText="Từ khóa" sortBy="#{item.contentKeyword}" filterBy="#{item.contentKeyword}" filterMatchMode="contains" >
                            #{item.contentKeyword}
                        </p:column>
                        <p:column headerText="Cú pháp" sortBy="#{item.syntaxPrefix}" filterBy="#{item.syntaxPrefix}" filterMatchMode="contains" >
                            #{item.syntaxPrefix}
                        </p:column>
                        <p:column headerText="Chú thích" sortBy="#{item.description}" filterBy="#{item.description}" filterMatchMode="contains" >
                            #{item.description}
                        </p:column>
                    </p:dataTable>

                    <p:confirmDialog modal="true" message="Bạn muốn xóa các bản ghi đã chọn?"  
                                     hideEffect="explode"  
                                     header="Xác nhận" severity="alert" widgetVar="deleteConfirm">  

                        <p:commandButton update="table" value="Có" oncomplete="deleteConfirm.hide()"  
                                         action="#{smsKeywordServiceMappingBean.remove()}">
                            <f:setPropertyActionListener target="#{tabBean.activeIndex}" value="0"/>
                        </p:commandButton>  
                        <p:commandButton value="Không" onclick="deleteConfirm.hide()" type="button" />   

                    </p:confirmDialog> 

                </h:form>
            </ui:define>

        </ui:composition>

    </body>
</html>

